package com.elcl.adapter;

import java.util.ArrayList;
import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.elcl.storage.ApplicationCache;

public abstract class BaseLVAdapter<T> extends BaseAdapter {
	protected List<T> list = new ArrayList<T>();
	protected int idLayout;

	public BaseLVAdapter(List<T> list, int idLayout) {
		super();
		this.list = list;
		this.idLayout = idLayout;
	}

	@Override
	public int getCount() {
		if (null != list && list.size() > 0) {
			return list.size();
		}else{
			return 0;
		}
	}

	@Override
	public Object getItem(int arg0) {
		if (null != list && list.size() > 0) {
			return list.get(arg0);
		}else{
			return null;
		}
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}
	
	
	public List<T> getListItem(){
		return list;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (null == convertView) {
			convertView = LayoutInflater.from(ApplicationCache.context).inflate(idLayout, null);
		}
		return getItemView(position, convertView, parent);
	}

	public abstract View getItemView(int position, View convertView, ViewGroup parent);

}
